package com.microframework.base.data.handler;

import java.util.List;
import java.util.Map;

import com.microframework.base.data.enums.SourceType;
import com.microframework.base.data.model.PageRequest;
import com.microframework.base.data.model.PageResult;
import com.microframework.boot.collect.model.domain.DataSourceConfig;

/**
 * 数据处理器接口 - 统一不同数据源的操作规范
 */
public interface DataHandler {

    /**
     * 判断是否支持指定类型的数据源
     */
    boolean supports(SourceType sourceType);

    /**
     * 测试数据源连接
     */
    boolean testConnection(DataSourceConfig config);

    /**
     * 获取数据(轮询模式)
     */
    List<Map<String, Object>> fetchData(DataSourceConfig config);

    /**
     * 订阅数据(推送模式)
     */
    default void subscribe(DataSourceConfig config, DataListener listener) {
        throw new UnsupportedOperationException("Subscribe not supported for this data source");
    }

    /**
     * 取消订阅
     */
    default void unsubscribe(DataSourceConfig config) {
        throw new UnsupportedOperationException("Unsubscribe not supported for this data source");
    }

    /**
     * 批量获取数据(分页支持)
     */
    default PageResult<Map<String, Object>> fetchBatchData(DataSourceConfig config, PageRequest pageRequest) {
        throw new UnsupportedOperationException("Batch fetch not supported for this data source");
    }

    /**
     * 写入数据
     */
    default void writeData(DataSourceConfig config, List<Map<String, Object>> data) {
        throw new UnsupportedOperationException("Write operation not supported for this data source");
    }
}